package com.cms.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.nutz.json.Json;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import tk.mybatis.mapper.common.Mapper;

import com.cms.utils.tools.PageBean;

public class BaseService<T>{

	  protected static Logger logger = LoggerFactory.getLogger(BaseService.class); 
		
	  @Autowired
	  private Mapper<T> mapper;//泛型装配
	  
	  @Transactional
	  public int insert(T t){
		  return mapper.insert(t);
	  }
	  
	  public T selectByPrimaryKey(Integer id) {
		return mapper.selectByPrimaryKey(id);
	  }
	  
	  public String setPage(List<T> list){
		PageBean<T> result = new PageBean<T>(list);
	   	Map<String,Object> map = new HashMap<String,Object>();
	    map.put("code",0);
	    map.put("count",result.getTotal());
	    map.put("data",result.getList());
        return Json.toJson(map);
	  }
}
